{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Train Your OpenVINO™ Model Using YoloV8 Trainer For Any Dataset Format\n",
    "\n",
    "[![Jupyter Notebook](https://img.shields.io/badge/jupyter-%23FA0F00.svg?style=for-the-badge&logo=jupyter&logoColor=white)](https://github.com/openvinotoolkit/datumaro/blob/develop/notebooks/08_e2e_example_yolo_ultralytics_trainer.ipynb)\n",
    "\n",
    "## Prerequisite\n",
    "### Download Six-sided Dice dataset\n",
    "This is [a download link for Six-sided Dice dataset in Kaggle](https://www.kaggle.com/datasets/nellbyler/d6-dice?resource=download). Please download using this link and extract to your workspace directory. Then, you will have a `d6-dice` directory with annotations and images in YOLO format as follows.\n",
    "\n",
    "```bash\n",
    "d6-dice\n",
    "├── Annotations\n",
    "│   ├── classes.txt\n",
    "│   ├── IMG_20191208_111228.txt\n",
    "│   ├── IMG_20191208_111246.txt\n",
    "│   ├── ...\n",
    "└── Images\n",
    "    ├── IMG_20191208_111228.jpg\n",
    "    ├── IMG_20191208_111246.jpg\n",
    "    ├── ...\n",
    "```\n",
    "\n",
    "However, for import compatibility, `obj.names` file must be added to `d6-dice/obj.names` filepath for import compatibility. This `obj.names` file includes the label names of the dataset, e.g., `[dice1, ..., dice6]`. Therefore, you can write it with the following simple code. Please see [Yolo Loose format](https://openvinotoolkit.github.io/datumaro/latest/docs/explanation/formats/yolo) for more details."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Copyright (C) 2023 Intel Corporation\n",
    "#\n",
    "# SPDX-License-Identifier: MIT\n",
    "\n",
    "import os\n",
    "\n",
    "root_dir = \"d6-dice\"\n",
    "\n",
    "names = \"\"\"\n",
    "dice1\n",
    "dice2\n",
    "dice3\n",
    "dice4\n",
    "dice5\n",
    "dice6\n",
    "\"\"\"\n",
    "\n",
    "fpath = os.path.join(root_dir, \"obj.names\")\n",
    "with open(fpath, \"w\") as fp:\n",
    "    fp.write(names)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Import dataset\n",
    "\n",
    "Firstly, we import this dataset using Datumaro Python API. The Six-sided Dice dataset has no subset split so that Datumaro will create \"default\" subset for it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dataset\n",
       "\tsize=250\n",
       "\tsource_path=./d6-dice\n",
       "\tmedia_type=<class 'datumaro.components.media.Image'>\n",
       "\tannotated_items_count=250\n",
       "\tannotations_count=1795\n",
       "subsets\n",
       "\tdefault: # of items=250, # of annotated items=250, # of annotations=1795, annotation types=['bbox']\n",
       "infos\n",
       "\tcategories\n",
       "\tlabel: ['dice1', 'dice2', 'dice3', 'dice4', 'dice5', 'dice6']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datumaro import Dataset\n",
    "\n",
    "dataset = Dataset.import_from(\"./d6-dice\", format=\"yolo\")\n",
    "dataset"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Split subsets and export dataset\n",
    "\n",
    "There is no subset split in the imported dataset. However, Ultralytics-YOLO trainer must require \"train\" and \"val\" subsets (\"test\" is optional). So, we will create \"train\", \"val\", and \"test\" splits from the imported dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Dataset\n",
       "\tsize=250\n",
       "\tsource_path=./d6-dice\n",
       "\tmedia_type=<class 'datumaro.components.media.Image'>\n",
       "\tannotated_items_count=250\n",
       "\tannotations_count=1795\n",
       "subsets\n",
       "\ttest: # of items=75, # of annotated items=75, # of annotations=517, annotation types=['bbox']\n",
       "\ttrain: # of items=125, # of annotated items=125, # of annotations=951, annotation types=['bbox']\n",
       "\tval: # of items=50, # of annotated items=50, # of annotations=327, annotation types=['bbox']\n",
       "infos\n",
       "\tcategories\n",
       "\tlabel: ['dice1', 'dice2', 'dice3', 'dice4', 'dice5', 'dice6']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "splited_dataset = dataset.transform(\n",
    "    \"random_split\", splits=[(\"train\", 0.5), (\"val\", 0.2), (\"test\", 0.3)]\n",
    ")\n",
    "splited_dataset"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we export the splited subsets to \"yolo_ultralytics\" format with `save_media=True` for Ultralytics-YOLO trainer. It is recommended to set `save_media=True`. If this option is enabled, Datumaro automatically copy-and-pastes the source images according to the correct directory structure of the target dataset format."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "splited_dataset.export(\"d6-dice-ultralytics\", \"yolo_ultralytics\", save_media=True)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Train model with Ultralytics YOLOv8 trainer\n",
    "\n",
    "At first, we will install Ultralytics YOLOv8 trainer to train the model and export it to [OpenVINO™ Intermediate Representation (IR)](https://docs.openvino.ai/latest/home.html). For export OpenVINO™ IR, we should install it with `export` extra (`ultralytics[export]`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install ultralytics[export]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os.path as osp\n",
    "\n",
    "# To give the Ultralytics YOLO trainer an arbitrary dataset path,\n",
    "# you must provide its absolute path.\n",
    "data_fpath = osp.abspath(osp.join(\"d6-dice-ultralytics\", \"data.yaml\"))\n",
    "model_fpath = osp.abspath(osp.join(\"d6-dice-project\", \"train\", \"weights\", \"best.pt\"))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Train yolov8n model\n",
    "We will train a `yolov8n` model on the Six-sided Dataset for 100 epochs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24268MiB)\n",
      "\u001b[34m\u001b[1myolo/engine/trainer: \u001b[0mtask=detect, mode=train, model=yolov8n.pt, data=/home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/data.yaml, epochs=100, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=d6-dice-project, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, hide_labels=False, hide_conf=False, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, fl_gamma=0.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, cfg=None, v5loader=False, tracker=botsort.yaml, save_dir=d6-dice-project/train2\n",
      "Overriding model.yaml nc=80 with nc=6\n",
      "\n",
      "                   from  n    params  module                                       arguments                     \n",
      "  0                  -1  1       464  ultralytics.nn.modules.Conv                  [3, 16, 3, 2]                 \n",
      "  1                  -1  1      4672  ultralytics.nn.modules.Conv                  [16, 32, 3, 2]                \n",
      "  2                  -1  1      7360  ultralytics.nn.modules.C2f                   [32, 32, 1, True]             \n",
      "  3                  -1  1     18560  ultralytics.nn.modules.Conv                  [32, 64, 3, 2]                \n",
      "  4                  -1  2     49664  ultralytics.nn.modules.C2f                   [64, 64, 2, True]             \n",
      "  5                  -1  1     73984  ultralytics.nn.modules.Conv                  [64, 128, 3, 2]               \n",
      "  6                  -1  2    197632  ultralytics.nn.modules.C2f                   [128, 128, 2, True]           \n",
      "  7                  -1  1    295424  ultralytics.nn.modules.Conv                  [128, 256, 3, 2]              \n",
      "  8                  -1  1    460288  ultralytics.nn.modules.C2f                   [256, 256, 1, True]           \n",
      "  9                  -1  1    164608  ultralytics.nn.modules.SPPF                  [256, 256, 5]                 \n",
      " 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          \n",
      " 11             [-1, 6]  1         0  ultralytics.nn.modules.Concat                [1]                           \n",
      " 12                  -1  1    148224  ultralytics.nn.modules.C2f                   [384, 128, 1]                 \n",
      " 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          \n",
      " 14             [-1, 4]  1         0  ultralytics.nn.modules.Concat                [1]                           \n",
      " 15                  -1  1     37248  ultralytics.nn.modules.C2f                   [192, 64, 1]                  \n",
      " 16                  -1  1     36992  ultralytics.nn.modules.Conv                  [64, 64, 3, 2]                \n",
      " 17            [-1, 12]  1         0  ultralytics.nn.modules.Concat                [1]                           \n",
      " 18                  -1  1    123648  ultralytics.nn.modules.C2f                   [192, 128, 1]                 \n",
      " 19                  -1  1    147712  ultralytics.nn.modules.Conv                  [128, 128, 3, 2]              \n",
      " 20             [-1, 9]  1         0  ultralytics.nn.modules.Concat                [1]                           \n",
      " 21                  -1  1    493056  ultralytics.nn.modules.C2f                   [384, 256, 1]                 \n",
      " 22        [15, 18, 21]  1    752482  ultralytics.nn.modules.Detect                [6, [64, 128, 256]]           \n",
      "Model summary: 225 layers, 3012018 parameters, 3012002 gradients, 8.2 GFLOPs\n",
      "\n",
      "Transferred 319/355 items from pretrained weights\n",
      "\u001b[34m\u001b[1mAMP: \u001b[0mrunning Automatic Mixed Precision (AMP) checks with YOLOv8n...\n",
      "\u001b[34m\u001b[1mAMP: \u001b[0mchecks passed ✅\n",
      "\u001b[34m\u001b[1moptimizer:\u001b[0m SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias\n",
      "\u001b[34m\u001b[1mtrain: \u001b[0mScanning /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/tra\u001b[0m\n",
      "\u001b[34m\u001b[1mtrain: \u001b[0mNew cache created: /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/train.cache\n",
      "\u001b[34m\u001b[1mval: \u001b[0mScanning /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/val..\u001b[0m\n",
      "\u001b[34m\u001b[1mval: \u001b[0mNew cache created: /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/val.cache\n",
      "Plotting labels to d6-dice-project/train2/labels.jpg... \n",
      "Image sizes 640 train, 640 val\n",
      "Using 8 dataloader workers\n",
      "Logging results to \u001b[1md6-dice-project/train2\u001b[0m\n",
      "Starting training for 100 epochs...\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      1/100      2.14G      1.615      4.381      1.119        112        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327          0          0          0          0\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      2/100      2.14G      1.364      4.068      1.016        118        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327    0.00656      0.248     0.0101    0.00435\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      3/100      2.14G      1.417       3.31      1.049        122        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327    0.00288      0.134    0.00556    0.00287\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      4/100      2.14G       1.36      2.637      1.051        126        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0162      0.648     0.0893      0.043\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      5/100      2.14G       1.36      2.334      1.052        162        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.015      0.616      0.111     0.0529\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      6/100      2.14G      1.427      2.235      1.063        187        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0211       0.91      0.204     0.0995\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      7/100      2.14G      1.389       2.19       1.05        198        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0228      0.968      0.236      0.137\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      8/100      2.14G      1.375      2.102      1.106        129        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0225       0.98      0.241      0.117\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "      9/100      2.14G      1.398      2.084       1.06        139        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0231          1      0.274      0.163\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     10/100      2.14G      1.419      2.062      1.072        109        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0233          1      0.288      0.176\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     11/100      2.14G      1.343      2.225      1.068        157        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0229      0.985      0.289      0.126\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     12/100      2.14G      1.431      2.125       1.08        168        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327     0.0243      0.986      0.272      0.125\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     13/100      2.14G      1.404      2.004      1.062        158        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.213        0.8      0.321      0.167\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     14/100      2.14G      1.365      1.995      1.064        177        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.343      0.369      0.368      0.207\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     15/100      2.14G      1.402      1.948       1.07        106        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.339      0.682      0.395      0.223\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     16/100      2.14G      1.387      1.906       1.06        139        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.275      0.559      0.368      0.211\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     17/100      2.26G       1.34      1.897      1.064        129        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.347      0.568      0.421      0.251\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     18/100      2.26G      1.292      1.918      1.042        188        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.617      0.303      0.379       0.23\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     19/100      2.26G      1.273      1.954      1.023        164        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.275      0.754      0.343      0.183\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     20/100      2.26G      1.358      1.803      1.026        133        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.301      0.839      0.437      0.221\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     21/100      2.26G      1.322      1.768      1.049        106        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.34      0.784      0.453      0.241\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     22/100      2.26G      1.293      1.775      1.056        131        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.262      0.644      0.402       0.25\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     23/100      2.26G      1.236      1.839      1.023        113        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.27      0.743      0.411      0.256\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     24/100      2.26G      1.348      1.758       1.01        223        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.343      0.885      0.519      0.332\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     25/100      2.26G       1.23      1.811      1.022        169        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.338      0.836      0.507      0.319\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     26/100      2.26G      1.188      1.745      1.013        119        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.418       0.76      0.531      0.346\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     27/100      2.26G      1.191      1.786      1.019        114        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.305       0.82       0.44       0.25\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     28/100      2.26G      1.207      1.639      1.009        134        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.418      0.866      0.567       0.34\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     29/100      2.26G      1.289      1.699      1.044        140        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.371       0.81      0.478      0.264\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     30/100      2.26G      1.297      1.612      1.019        119        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.494      0.772      0.605      0.303\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     31/100      2.26G      1.256      1.598      1.009        123        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.381        0.7      0.488      0.277\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     32/100      2.26G      1.213      1.655      1.016        125        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.346      0.772      0.499      0.279\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     33/100      2.26G      1.231      1.559      1.019        195        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327        0.5      0.815      0.638      0.341\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     34/100      2.26G      1.233      1.536      1.032        134        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.482      0.798      0.671      0.414\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     35/100      2.26G      1.144      1.546     0.9998        125        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.309      0.642      0.419      0.249\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     36/100      2.26G      1.213      1.579      1.004        114        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.438      0.756      0.564      0.356\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     37/100      2.26G       1.21      1.533      1.008        128        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.501       0.75      0.629      0.377\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     38/100      2.26G      1.238      1.469      1.037        168        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.348      0.621       0.44      0.279\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     39/100      2.26G       1.22      1.492      1.042        105        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.575       0.73      0.665      0.422\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     40/100      2.26G      1.243      1.425      1.016        113        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.612      0.741      0.691      0.447\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     41/100      2.26G      1.229      1.482      1.026         76        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.639      0.821      0.751      0.482\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     42/100      2.26G      1.142      1.438     0.9861        122        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.626      0.787      0.756      0.476\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     43/100      2.26G       1.12      1.359     0.9938        125        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.61       0.79       0.74      0.476\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     44/100      2.26G      1.139      1.398      1.007        129        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.649      0.792      0.802      0.512\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     45/100      2.26G      1.137      1.294     0.9998        156        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.671      0.822      0.807       0.51\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     46/100      2.26G      1.138      1.291      1.031        152        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.539      0.697      0.673      0.429\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     47/100      2.26G      1.184      1.292      1.013        143        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.701      0.802      0.835      0.529\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     48/100      2.26G      1.213      1.261      1.034        148        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327        0.7      0.847      0.834      0.541\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     49/100      2.26G      1.159      1.251     0.9938        144        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.727      0.852       0.83      0.495\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     50/100      2.26G      1.195      1.226      1.038         94        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.71       0.84      0.846      0.517\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     51/100      2.26G      1.127      1.236     0.9852        155        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.674      0.781      0.805      0.517\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     52/100      2.26G      1.174      1.236      1.029        132        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.687      0.777      0.831      0.544\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     53/100      2.26G      1.105      1.199      1.018        127        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.615      0.765      0.762      0.496\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     54/100      2.26G      1.119      1.191      0.981        169        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.619      0.834      0.822      0.534\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     55/100      2.26G      1.069      1.143      0.972        133        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.759      0.843      0.886      0.559\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     56/100      2.26G      1.134      1.117     0.9923        115        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.687      0.832      0.848      0.555\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     57/100      2.26G      1.128       1.16     0.9833        161        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.736       0.85      0.882      0.565\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     58/100      2.26G      1.109      1.129     0.9741        151        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.804      0.805      0.884      0.578\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     59/100       2.4G       1.17       1.14      1.016         81        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.803      0.854      0.901      0.563\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     60/100       2.4G      1.133        1.1      1.014        170        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.803      0.858      0.904      0.547\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     61/100       2.4G      1.102      1.084     0.9943        144        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.807      0.852      0.913      0.578\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     62/100       2.4G      1.063      1.086     0.9789        108        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.842      0.851      0.899      0.563\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     63/100       2.4G       1.09      1.082     0.9843        121        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.841      0.866      0.927       0.57\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     64/100       2.4G      1.046       1.09      0.973        115        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.825      0.871      0.927      0.581\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     65/100       2.4G      1.098      1.056      0.961        227        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.781      0.887      0.913      0.581\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     66/100       2.4G      1.027      1.001     0.9675        137        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.845      0.859      0.917      0.546\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     67/100       2.4G      1.098      1.044     0.9798        153        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.895      0.839      0.932      0.577\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     68/100       2.4G      1.105      1.018     0.9884        186        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.812      0.874       0.91      0.575\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     69/100       2.4G       1.08      1.011     0.9878        133        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.837      0.818      0.896      0.566\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     70/100       2.4G       1.02       1.04     0.9831         76        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.824      0.905      0.937      0.593\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     71/100       2.4G      1.023      1.022     0.9531        147        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.807       0.89      0.935      0.587\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     72/100       2.4G      1.103     0.9996      1.025         78        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.875      0.845      0.921      0.577\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     73/100       2.4G      1.039     0.9157      0.975         74        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.835      0.868      0.934      0.578\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     74/100       2.4G      1.103      1.004     0.9866        153        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.886      0.866      0.944       0.59\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     75/100       2.4G      1.043     0.9381     0.9686        185        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.895      0.882      0.947      0.571\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     76/100       2.4G      1.035     0.9351     0.9714        110        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.813      0.922      0.944      0.591\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     77/100       2.4G      1.019     0.9196     0.9839        101        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.843      0.896      0.943      0.593\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     78/100       2.4G      1.059     0.9575     0.9794         95        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.88      0.882      0.949      0.559\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     79/100       2.4G      1.049     0.9213      0.972        117        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327        0.9      0.895      0.944      0.604\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     80/100       2.4G      1.015      0.878     0.9548        158        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.902      0.901      0.955      0.592\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     81/100       2.4G      1.014      0.901     0.9594        117        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.917      0.872      0.949      0.605\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     82/100       2.4G       1.07     0.9242      1.001        193        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.896       0.92      0.957       0.58\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     83/100       2.4G      1.018     0.8704     0.9674         96        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.903      0.934      0.959      0.591\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     84/100       2.4G      1.003      0.859     0.9545        120        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.913      0.866      0.961      0.611\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     85/100       2.4G      1.061     0.8796     0.9544        195        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.894      0.905      0.959      0.609\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     86/100       2.4G      1.069     0.9033     0.9926        146        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.87      0.911      0.958      0.606\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     87/100       2.4G       1.02     0.8343      0.961        127        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.931      0.901      0.964      0.613\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     88/100       2.4G      1.026     0.8555     0.9712        126        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.918      0.924      0.965       0.61\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     89/100       2.4G      1.039     0.8231     0.9747        103        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.876      0.934      0.963      0.602\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     90/100       2.4G     0.9811     0.8461     0.9502        178        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.895      0.879      0.959      0.608\n",
      "Closing dataloader mosaic\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     91/100       2.4G     0.9937      0.774      1.009        108        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327       0.89      0.916      0.956      0.594\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     92/100       2.4G      0.996      0.773      1.009        104        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.896      0.944      0.956      0.605\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     93/100       2.4G      1.006     0.7829      1.015        103        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.898       0.92      0.957      0.595\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     94/100       2.4G      1.016     0.7947      1.019        115        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.893      0.934      0.958      0.601\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     95/100       2.4G     0.9838     0.7514      1.008        117        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.915      0.924      0.964      0.607\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     96/100       2.4G      0.983     0.7637          1        112        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.909      0.919      0.964      0.603\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     97/100       2.4G     0.9728     0.7337      1.007         94        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.914      0.919      0.964      0.601\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     98/100       2.4G     0.9786     0.7598     0.9967         73        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.901       0.93      0.963      0.607\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "     99/100       2.4G     0.9658     0.7412     0.9884         88        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.925      0.918      0.963      0.601\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n",
      "    100/100       2.4G     0.9697     0.7439     0.9898         96        640: 1\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.904      0.934      0.964      0.584\n",
      "\n",
      "100 epochs completed in 0.293 hours.\n",
      "Optimizer stripped from d6-dice-project/train2/weights/last.pt, 6.2MB\n",
      "Optimizer stripped from d6-dice-project/train2/weights/best.pt, 6.2MB\n",
      "\n",
      "Validating d6-dice-project/train2/weights/best.pt...\n",
      "Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24268MiB)\n",
      "Model summary (fused): 168 layers, 3006818 parameters, 0 gradients, 8.1 GFLOPs\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         50        327      0.931      0.902      0.964      0.611\n",
      "                 dice1         50         72      0.997      0.972      0.989      0.582\n",
      "                 dice2         50         48      0.933      0.917      0.976      0.651\n",
      "                 dice3         50         51      0.909      0.782      0.938      0.647\n",
      "                 dice4         50         40      0.887        0.9      0.949      0.636\n",
      "                 dice5         50         68      0.925        0.9      0.966       0.59\n",
      "                 dice6         50         48      0.934      0.938      0.966      0.558\n",
      "Speed: 0.8ms preprocess, 0.8ms inference, 0.0ms loss, 1.0ms postprocess per image\n",
      "Results saved to \u001b[1md6-dice-project/train2\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!yolo detect train model=yolov8n.pt data={data_fpath} epochs=100 imgsz=640 project=d6-dice-project"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Evaluate on the test set\n",
    "\n",
    "Now, we have the trained model saved in `model_fpath`. We can evaluate this model on the test dataset as follows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24268MiB)\n",
      "Model summary (fused): 168 layers, 3006818 parameters, 0 gradients, 8.1 GFLOPs\n",
      "\u001b[34m\u001b[1mval: \u001b[0mScanning /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/test.\u001b[0m\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  m\n",
      "                   all         75        517      0.953      0.932      0.975      0.632\n",
      "                 dice1         75         83      0.977      0.952      0.987      0.662\n",
      "                 dice2         75        101      0.951      0.931      0.976      0.649\n",
      "                 dice3         75         84      0.962      0.903       0.96      0.596\n",
      "                 dice4         75         82       0.93       0.97       0.98      0.615\n",
      "                 dice5         75         88      0.938       0.92      0.969      0.629\n",
      "                 dice6         75         79       0.96      0.914      0.976      0.642\n",
      "Speed: 1.5ms preprocess, 1.0ms inference, 0.0ms loss, 26.3ms postprocess per image\n",
      "Results saved to \u001b[1m/home/vinnamki/ultralytics/runs/detect/val4\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!yolo detect val model={model_fpath} data={data_fpath} split=test"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Export the trained model to OpenVINO™ IR\n",
    "\n",
    "So far, we have been able to successfully train our `YOLOv8` model by converting the dataset format using Datumaro and passing it to the Ultralytics YOLOv8 trainer CLI. The final step is exporting the trained model to [OpenVINO™ IR](https://docs.openvino.ai/latest/home.html) to accelerate model inference on any Intel™ device."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CPU\n",
      "Model summary (fused): 168 layers, 3006818 parameters, 0 gradients, 8.1 GFLOPs\n",
      "\n",
      "\u001b[34m\u001b[1mPyTorch:\u001b[0m starting from /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best.pt with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 10, 8400) (5.9 MB)\n",
      "\n",
      "\u001b[34m\u001b[1mONNX:\u001b[0m starting export with onnx 1.13.1...\n",
      "\u001b[34m\u001b[1mONNX:\u001b[0m export success ✅ 0.4s, saved as /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best.onnx (11.7 MB)\n",
      "\n",
      "\u001b[34m\u001b[1mOpenVINO:\u001b[0m starting export with openvino 2022.3.0-9052-9752fafe8eb-releases/2022/3...\n",
      "\u001b[34m\u001b[1mOpenVINO:\u001b[0m export success ✅ 0.7s, saved as /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best_openvino_model/ (11.8 MB)\n",
      "\n",
      "Export complete (1.4s)\n",
      "Results saved to \u001b[1m/home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights\u001b[0m\n",
      "Predict:         yolo predict task=detect model=/home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best_openvino_model imgsz=640 \n",
      "Validate:        yolo val task=detect model=/home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best_openvino_model imgsz=640 data=/home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/data.yaml \n",
      "Visualize:       https://netron.app\n"
     ]
    }
   ],
   "source": [
    "!yolo detect export model={model_fpath} format=openvino"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "datumaro",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "f1f3f1edb00d0bd7e23d51df1aa8d48a9cf9f8b2f9be1bd0ed7e776e90e03d96"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
